namespace SinaFinanceBaseClassLibrary
{
    using System;
    using System.Collections.Generic;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Media;

    public class AxisSysMarks : UserControl, IAxisMarks
    {
        private int controlZindex = 20;
        private bool isSameColor = false;
        private Canvas parentCanvas;
        private double tickMarkAngle = 0.0;

        public void DrawAxisMarks(double leftStart, double topStart, double axisUnitSpan, List<string> axisData, XorYAxisEnum axisEnum)
        {
            if ((axisData != null) && !axisData.Count.Equals(0))
            {
                for (int i = 0; i < axisData.Count; i++)
                {
                    double num4;
                    double num5;
                    TextBlock block = new TextBlock {
                        Text = axisData[i],
                        TextAlignment = TextAlignment.Center
                    };
                    block.SetValue(Canvas.ZIndexProperty, this.ControlZindex);
                    this.parentCanvas.Children.Add(block);
                    double actualHeight = block.ActualHeight;
                    double actualWidth = block.ActualWidth;
                    if (axisEnum.Equals(XorYAxisEnum.xAxis))
                    {
                        num4 = (leftStart + (axisUnitSpan * i)) - (actualWidth * 0.5);
                        num5 = topStart + 5.0;
                        block.Margin = new Thickness(num4, num5, 0.0, 0.0);
                        block.Foreground = new SolidColorBrush(Color.FromArgb(0xff, 30, 0x90, 0xff));
                        if (this.tickMarkAngle > 0.0)
                        {
                            RotateTransform transform = new RotateTransform {
                                Angle = this.tickMarkAngle
                            };
                            block.RenderTransform = transform;
                        }
                    }
                    else
                    {
                        num4 = leftStart;
                        if ((axisEnum.Equals(XorYAxisEnum.leftYaxis) || axisEnum.Equals(XorYAxisEnum.kYAxis)) || axisEnum.Equals(XorYAxisEnum.volumnYaxis))
                        {
                            num4 = (leftStart > actualWidth) ? ((leftStart - actualWidth) - 2.0) : 0.0;
                        }
                        else
                        {
                            num4 = (leftStart > actualWidth) ? (leftStart + 2.0) : 0.0;
                        }
                        num5 = (topStart + (axisUnitSpan * i)) - (actualHeight * 0.5);
                        block.Margin = new Thickness(num4, num5, 0.0, 0.0);
                        if (this.isSameColor && axisEnum.Equals(XorYAxisEnum.volumnYaxis))
                        {
                            block.Foreground = new SolidColorBrush(Colors.Gray);
                        }
                        else if (this.isSameColor && axisEnum.Equals(XorYAxisEnum.kYAxis))
                        {
                            block.Foreground = new SolidColorBrush(Colors.Red);
                        }
                        else if (i < (axisData.Count / 2))
                        {
                            block.Foreground = new SolidColorBrush(Colors.Red);
                        }
                        else if (i.Equals((int) (axisData.Count / 2)))
                        {
                            block.Foreground = new SolidColorBrush(Colors.White);
                        }
                        else
                        {
                            block.Foreground = new SolidColorBrush(Color.FromArgb(0xff, 30, 0x90, 0xff));
                        }
                    }
                }
            }
        }

        public int ControlZindex
        {
            get
            {
                return this.controlZindex;
            }
            set
            {
                this.controlZindex = value;
            }
        }

        public bool IsSameColor
        {
            get
            {
                return this.isSameColor;
            }
            set
            {
                this.isSameColor = value;
            }
        }

        public Canvas ParentCanvas
        {
            get
            {
                return this.parentCanvas;
            }
            set
            {
                this.parentCanvas = value;
            }
        }

        public double TickMarkAngle
        {
            get
            {
                return this.tickMarkAngle;
            }
            set
            {
                this.tickMarkAngle = value;
            }
        }
    }
}
